package ru.neoflex.chugunov;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;

import ru.neoflex.chugunov.database.WordJDBCDAO;

public class Scheduler {
	private WordJDBCDAO jd = new WordJDBCDAO();
	private List<Word> allWords;
	private List<Word> dayWords;
	private Random rand = new Random();
	
	public List<Word> addAllWordsForLearn() {
		Scan scan = new Scan();
		Long today = new Date().getTime();
		allWords = new ArrayList<>();
		scan.setDict(jd.printAll());
		for (int i=0;i<scan.getDict().size(); i++) {
			if(today >= scan.getDict().get(i).getLastTimeMillis()+scan.getDict().get(i).getInterval()) {
				allWords.add(scan.getDict().get(i));
			}
		}
		return allWords;
	}
	
	public List<Word> addDayLearn(List<Word> allWords) {
		dayWords = new ArrayList<>();
		Word w;
		if (allWords.size() > 30) {
			for (; dayWords.size()<30;) {
				w = allWords.get(rand.nextInt(allWords.size()));
				if(!dayWords.contains(w)) {
					dayWords.add(w); 
				}	
			}
		} else dayWords = new ArrayList<>(allWords);	
		return dayWords;		
	}	
}
